package weather;

import android.content.Context;
import android.os.AsyncTask;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;

/**
 * Created by sirius_swu on 2017/3/15.
 */
public class WeatherTask extends AsyncTask<String, Void, String> {
    private JSONObject jsonObject;
    private String locationVar;

    Context context;
    TextView location;

    public WeatherTask(Context context, TextView location) {
        super();
        this.context = context;
        this.location = location;
    }

    @Override
    protected String doInBackground(String... params) {
//        GpsSearch gpsSearch = new GpsSearch(context);
//        jsonObject = gpsSearch.retJson();
//        JSONObject location = jsonObject.getJSONObject("showapi_res_body").getJSONObject("cityInfo");
//        locationVar = location.getString("c7")+"省"+location.getString("c3")+"市";
//        return locationVar;
        return null;
    }

//    @Override
//    protected void onPreExecute() {
//        super.onPreExecute();
//        locationVar = "zhuhai";
//        location.setText(locationVar);
//    }

    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
        JSONObject locationValue = jsonObject.getJSONObject("showapi_res_body").getJSONObject("cityInfo");
        locationVar = locationValue.getString("c7")+"省"+locationValue.getString("c3")+"市";
        location.setText(locationVar);
    }
}
